package com.interest.web.controller.business;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.interest.business.domain.InterestRedeemCode;
import com.interest.business.domain.vo.InterestQueryVo;
import com.interest.common.annotation.Log;
import com.interest.common.core.controller.BaseController;
import com.interest.common.core.domain.AjaxResult;
import com.interest.common.core.page.TableDataInfo;
import com.interest.common.enums.BusinessType;
import com.interest.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.interest.business.domain.InterestInterest;
import com.interest.business.service.IInterestInterestService;
import org.springframework.web.multipart.MultipartFile;

/**
 * 权益管理Controller
 * 
 * @author hzf
 * @date 2024-03-23
 */
@RestController
@RequestMapping("/business/interest")
public class InterestInterestController extends BaseController
{
    @Autowired
    private IInterestInterestService interestInterestService;

    /**
     * 查询权益管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:interest:list')")
    @GetMapping("/list")
    public TableDataInfo list(InterestQueryVo interestInterest)
    {
        startPage();
        List<InterestInterest> list = interestInterestService.selectInterestInterestList(interestInterest);
        return getDataTable(list);
    }

    @GetMapping("/listAllInterest")
    public AjaxResult listAllInterest()
    {
        List<InterestInterest> list = interestInterestService.selectInterestInterestList(null);
        return AjaxResult.success(list);
    }

    /**
     * 获取权益管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:interest:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(interestInterestService.selectInterestInterestById(id));
    }

    /**
     * 新增权益管理
     */
    @PreAuthorize("@ss.hasPermi('business:interest:add')")
    @Log(title = "权益管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(MultipartFile file,  InterestInterest interestInterest) throws IOException {
        return toAjax(interestInterestService.insertInterestInterest(file,interestInterest));
    }

    /**
     * 修改权益管理
     */
    @PreAuthorize("@ss.hasPermi('business:interest:edit')")
    @Log(title = "权益管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(MultipartFile file,  InterestInterest interestInterest) throws IOException {
        return toAjax(interestInterestService.updateInterestInterest(file,interestInterest));
    }

    /**
     * 删除权益管理
     */
    @PreAuthorize("@ss.hasPermi('business:interest:remove')")
    @Log(title = "权益管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(interestInterestService.deleteInterestInterestByIds(ids));
    }

    /**
     * 下载导入模板
     * @param response
     */
    @PreAuthorize("@ss.hasPermi('business:interest:add')")
    @Log(title = "权益管理", businessType = BusinessType.INSERT)
    @PostMapping("/downloadCodeTemplate")
    public void downloadCodeTemplate(HttpServletResponse response){
        ExcelUtil<InterestRedeemCode> util = new ExcelUtil<InterestRedeemCode>(InterestRedeemCode.class);
        util.importTemplateExcel(response, "权益兑换码数据");
    }
}
